using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Unibot
{

    //HARD CODED List of textures, names and links
    //used for easy loading and unloading of textures

    //Currently each sprite type is a file... which part of the file to use is still up to the objects using this class and enum

    public enum SpriteType
    {
        //When this list is changed or edited, be sure to make the appropriate changes is in SpriteSheet.InitilizeSprites
        Player,
        Ground_Metal,
        Goal,
    }

    public class SpriteSheet
    {
        private static SortedList<SpriteType, SpriteSheet> sprites;

        private SpriteType spritetype;        //To only match above enums
        private String name;                //name for context pipeline
        private String contentlink;         //the path to the file
        private Texture2D texture;       //the texture object of the sheet
        private ContentManager content;     //The content manager for this sheet

        private SpriteSheet(SpriteType type, String name, String link, ContentManager cm)
        {
            this.spritetype = type;
            this.name = name;
            this.contentlink = link;
            this.content = cm;
        }

        //loads the sprite into the content pipeline if not already loaded (does not reload)
        //be sure to call again if content.Unload() is called
        public void Load()
        {
            texture = content.Load<Texture2D>(contentlink);
        }

        public String getName() { return name; }


        //needed?
        public Texture2D getTexture() { return texture; }

        //returns the particular sprite (if it exists)
        //dont know what happens if dne
        public static void getSprite(SpriteType type, out SpriteSheet sprite)
        {
            sprites.TryGetValue(type,out sprite);
        }


        //does not load the textures but preps them
        public static void InitializeSprites(ContentManager cm)
        {

            sprites = new SortedList<SpriteType, SpriteSheet>();
            
            //init vars
            SpriteType spriteID;
            String name;
            String contentlink;

            //0 - Player
            spriteID = SpriteType.Player;
            name = "Unibot";
            contentlink ="Sprites//Unibot";
            sprites.Add(SpriteType.Player, new SpriteSheet(spriteID,name,contentlink,cm));


            //1 - Ground Metal
            spriteID = SpriteType.Ground_Metal;
            name = "blocks";
            contentlink = "Sprites//blocks";
            sprites.Add(SpriteType.Ground_Metal, new SpriteSheet(spriteID, name, contentlink, cm));

            //2 - Goal
            spriteID = SpriteType.Goal;
            name = "exit";
            contentlink = "Sprites//exit";
            sprites.Add(SpriteType.Goal, new SpriteSheet(spriteID, name, contentlink, cm));

        }
    }

}
